//version:1.0.0
window.save = function () {
    let data = window.vueInstance.$children[0].$children[0].$children[0].$children[1].$children[1].$children[0];
    if (!data.$route.query.ticket && !data.$route.query.projid) return;
    data.formValidate(['form']);
    data.customBackFun();
};
export default {
    data() {
        return {
            form:{
                aic169: {
                    value: '',
                    p: 'H'
                },
                bac062: {
                    value: '',
                    p: 'H'
                },
                bac063: {
                    value: '',
                    p: 'H'
                },
                aic160: {
                    value: '',
                    p: 'R'
                },
                aae146: {
                    key: '',
                    value: '',
                    p: 'R'
                },
                ljnx: {
                    value: '0-0',
                    p: 'D'
                },
                aae160: {
                    key: '',
                    value: '',
                    p: 'R'
                },
                aae201: {
                    value: '0-0',
                    p: 'D'
                },
                aae200: {
                    value: '0-0',
                    p: 'D'
                },
                aae165: {
                    value: '',
                    p: 'D'
                },
                aae201: {
                    value: '0-0',
                    p: 'D'
                },
                aae200: {
                    value: '0-0',
                    p: 'D'
                },
                aic167: {
                    value: '',
                    p: 'D'
                },
                aic166: {
                    value: '',
                    p: 'D'
                },
                bic119: {
                    key: '',
                    value: '',
                    p: 'R'
                },
                bic121: {
                    key: '',
                    value: '',
                    p: 'R'
                },
                bic120: {
                    key: '',
                    value: '',
                    p: 'R'
                },
                bic126: {
                    value: '',
                    p: 'D'
                },
                bic122: {
                    value: '',
                    p: 'R'
                },
                bic123: {
                    value: '',
                    p: 'R'
                },
                bic124: {
                    value: '',
                    p: 'R'
                },
                bic125: {
                    value: '',
                    p: 'R'
                },
                aae007: {
                    value: '',
                    p: 'R'
                },
                bae011s: {
                    key: '',
                    value: '',
                    p: 'E'
                },
                bae012s: {
                    key: '',
                    value: '',
                    p: 'E'
                },
                bae013s: {
                    key: '',
                    value: '',
                    p: 'E'
                },
                aae006s: {
                    value: '',
                    p: 'E'
                },
                aae004: {
                    value: '',
                    p: 'R'
                },
                aae005: {
                    value: '',
                    p: 'R'
                },
                bae011: {
                    key: '',
                    value: '',
                    p: 'E'
                },
                bae012: {
                    key: '',
                    value: '',
                    p: 'E'
                },
                bae013: {
                    key: '',
                    value: '',
                    p: 'E'
                },
                aae006: {
                    value: '',
                    p: 'E'
                },
                aae145: {
                    key: '',
                    value: '',
                    p: 'R'
                },
                aaz065: {
                    key: '',
                    value: '',
                    p: 'R'
                },
                aae010: {
                    value: '',
                    p: 'R'
                },
                aaf002: {
                    value: '',
                    p: 'R'
                },
                aae010: {
                    value: '',
                    p: 'R'
                },
                bac049: {
                    value: '',
                    p: 'D'
                },
                xbfylj: {
                    value: '',
                    p: 'D'
                },
                xbfa1: {
                    value: '',
                    p: 'D'
                },
                xbfgrylj: {
                    value: '',
                    p: 'D'
                },
                xbfa2: {
                    value: '',
                    p: 'D'
                },
                xbfgdylj: {
                    value: '',
                    p: 'D'
                },
                xbfa3: {
                    value: '',
                    p: 'D'
                },
                xbfyylj: {
                    value: '',
                    p: 'D'
                },
                lbfylj: {
                    value: '',
                    p: 'D'
                },
                lbfa1: {
                    value: '',
                    p: 'D'
                },
                lbfgrylj: {
                    value: '',
                    p: 'D'
                },
                lbfa2: {
                    value: '',
                    p: 'D'
                },
                lbfgdylj: {
                    value: '',
                    p: 'D'
                },
                lbfa3: {
                    value: '',
                    p: 'D'
                },
                lbfyylj: {
                    value: '',
                    p: 'D'
                },
                xlbdylj: {
                    value: '',
                    p: 'D'
                },
                xlbda1: {
                    value: '',
                    p: 'D'
                },
                xlbdtjj: {
                    value: '',
                    p: 'D'
                },
                xlbda2: {
                    value: '',
                    p: 'D'
                },
                xlbdyfylj: {
                    value: '',
                    p: 'D'
                },
                xlbda3: {
                    value: '',
                    p: 'D'
                },
                dnzdylj: {
                    value: '',
                    p: 'D'
                },
                dnzda1: {
                    value: '',
                    p: 'D'
                },
                yhdylj: {
                    value: '',
                    p: 'D'
                },
                yhda2: {
                    value: '',
                    p: 'D'
                },

            },
            dialogTableVisible01:false,
            dialogTableVisible02:false,
            dialogTableVisible03:false,
            activeNames:['1','2','3'],
            activeName2: '1',
            tableData1: {},
            tableData2: {},
            tableData3: {},
            tableData4: {},
            tableData5: {},
            tableData6: {},
            panel: {},

            rules:{
                aic160: [
                    {required: true, validator: this.$rules.test_noBlank, trigger: 'blur'}

                ],
                aae146: [
                    {required: true, validator: this.$rules.test_noBlank, trigger: 'change'}

                ],
                aae160: [
                    {required: true, validator: this.$rules.test_noBlank, trigger: 'change'}

                ],
                bic119: [
                    {required: true, validator: this.$rules.test_noBlank, trigger: 'change'}

                ],
                bic121: [
                    {required: true, validator: this.$rules.test_noBlank, trigger: 'change'}

                ],
                bic120: [
                    {required: true, validator: this.$rules.test_noBlank, trigger: 'change'}

                ],
                bic122: [
                    {required: true, validator: this.$rules.test_noBlank, trigger: 'blur'}

                ],
                bic123: [
                    {required: true, validator: this.$rules.test_noBlank, trigger: 'blur'}

                ],
                bic124: [
                    {required: true, validator: this.$rules.test_noBlank, trigger: 'blur'}

                ],
                bic125: [
                    {required: true, validator: this.$rules.test_noBlank, trigger: 'blur'}

                ],
                aae007: [
                    {required: true, validator: this.$rules.postcode, trigger: 'blur'}

                ],
                aae004: [
                    {required: true, validator: this.$rules.test_noBlank, trigger: 'blur'}

                ],
                aae005: [
                    {required: true, validator: this.$rules.mobile, trigger: 'blur'}

                ],
                aae145: [
                    {required: true, validator: this.$rules.test_noBlank, trigger: 'change'}

                ],
                aaz065: [
                    {required: true, validator: this.$rules.test_noBlank, trigger: 'change'}

                ],
                aae010: [
                    {required: true, validator: this.$rules.test_noBlank, trigger: 'blur'}

                ],
                aaf002: [
                    {required: true, validator: this.$rules.test_noBlank, trigger: ['change','blur']}

                ],
                aae010: [
                    {required: true, validator: this.$rules.test_noBlank, trigger: 'blur'}

                ],
                bac049: [
                    { validator: this.$rules.test_noBlank, trigger: 'blur'}

                ],

            },
            codeTypes:{
                AAE146:[],
                AAE145:[],
                BIC119:[],
                BIC121:[],
                BIC120:[],
                BAE007:[],
                BAE008:[],
                BAE009:[],
                AAZ065:[],

            },
            codeTypeFilters:{
                BAE008:" aaa102 like substr(':bae011',0,2)||'%' and aaa102 like '%00' ",
                BAE009:" aaa102 like substr(':bae012',0,4)||'%'",

            },
            pager: {
                page: 1,
                size: 10
            },
            total: 0,
        }
    },
    computed: {
        refresh() {
            return localStorage.getItem('refresh') || false;
        },
        functionId() {
            if (this.$store.getters.init.path !== this.$route.path) return;
            if (this.$store.getters.init.mdParam === null || this.$store.getters.init.mdParam === undefined) return;
            if (this.$store.getters.init.mdParam.functionid === undefined) return;
            return this.$store.getters.init.mdParam.functionid;
        },
        backFun() {
            return this.$store.getters.backFun;
        },
        init_formData() {
            if (this.$store.getters.init.path !== this.$route.path)  return;
            return this.$store.getters.init.form;
        },
        doInitformData: {
            get: function () {
                if (this.$store.getters.common === null) return [];
                if (this.$store.getters.common.path !== this.$route.path) return;
                return this.$store.getters.common.formData;
            },
            set: function (newValue) {
                if (newValue.path !== this.$route.path) return;
                return newValue;
            }
        },
        init_panel() {
            if (this.$store.getters.init.path !== this.$route.path)  return;
            return this.$store.getters.init.panel;
        },
        doInitpanel: {
            get: function () {
                if (this.$store.getters.common === null) return [];
                if (this.$store.getters.common.path !== this.$route.path) return;
                return this.$store.getters.common.panel;
            },
            set: function (newValue) {
                if (newValue.path !== this.$route.path) return;
                return newValue;
            }
        },
        init_tableData1() {
            return this.$store.getters.init.tableData1;
        },
        doInittableData1: {
            get: function () {
                if (this.$store.getters.common === null) return [];
                if (this.$store.getters.common.path !== this.$route.path) return;
                return this.$store.getters.common.tableData1;
            },
            set: function (newValue) {
                if (newValue.path !== this.$route.path) return;
                return newValue;
            }
        },
        init_tableData2() {
            return this.$store.getters.init.tableData2;
        },
        doInittableData2: {
            get: function () {
                if (this.$store.getters.common === null) return [];
                if (this.$store.getters.common.path !== this.$route.path) return;
                return this.$store.getters.common.tableData2;
            },
            set: function (newValue) {
                if (newValue.path !== this.$route.path) return;
                return newValue;
            }
        },
        init_tableData3() {
            return this.$store.getters.init.tableData3;
        },
        doInittableData3: {
            get: function () {
                if (this.$store.getters.common === null) return [];
                if (this.$store.getters.common.path !== this.$route.path) return;
                return this.$store.getters.common.tableData3;
            },
            set: function (newValue) {
                if (newValue.path !== this.$route.path) return;
                return newValue;
            }
        },
        init_tableData4() {
            return this.$store.getters.init.tableData4;
        },
        doInittableData4: {
            get: function () {
                if (this.$store.getters.common === null) return [];
                if (this.$store.getters.common.path !== this.$route.path) return;
                return this.$store.getters.common.tableData4;
            },
            set: function (newValue) {
                if (newValue.path !== this.$route.path) return;
                return newValue;
            }
        },
        init_tableData5() {
            return this.$store.getters.init.tableData5;
        },
        doInittableData5: {
            get: function () {
                if (this.$store.getters.common === null) return [];
                if (this.$store.getters.common.path !== this.$route.path) return;
                return this.$store.getters.common.tableData5;
            },
            set: function (newValue) {
                if (newValue.path !== this.$route.path) return;
                return newValue;
            }
        },
        init_tableData6() {
            return this.$store.getters.init.tableData6;
        },
        doInittableData6: {
            get: function () {
                if (this.$store.getters.common === null) return [];
                if (this.$store.getters.common.path !== this.$route.path) return;
                return this.$store.getters.common.tableData6;
            },
            set: function (newValue) {
                if (newValue.path !== this.$route.path) return;
                return newValue;
            }
        },

    },
    created() {
        let param = {
            path: this.$route.path,
            codeTypes:this.codeTypes,
            codeTypeFilters: window.btoa(JSON.stringify(this.codeTypeFilters)),
            form:this.form,
            tableData1:this.tableData1,
            tableData2:this.tableData2,
            tableData3:this.tableData3,
            tableData4:this.tableData4,
            tableData5:this.tableData5,
            tableData6:this.tableData6,
            panel:this.panel

        };
        if (this.refresh === 'true') {
            this.$store.dispatch('SET_INIT', param);
        }
        if (this.$route.query.keepAlive === undefined) {
            this.$store.dispatch('SET_INIT', param);
        }
    },
    watch: {
        refresh: {
            handler(value) {
                return value;
            },
            deep: true
        },
        init_formData: {
            handler(value) {
                if (value == undefined) return;
                this.$refs.form.clearValidate();
                this.getformData(value);
            },
            deep: true
        },
        doInitformData: {
            handler(value) {
                if (value == undefined) return;
                this.getformData(value);
            },
            deep: true
        },
        init_panel: {
            handler(value) {
                if (value == undefined) return;
                this.$refs.panel.clearValidate();
                this.getpanel(value);
            },
            deep: true
        },
        doInitpanel: {
            handler(value) {
                if (value == undefined) return;
                this.getpanel(value);
            },
            deep: true
        },
        doInittableData1: {
            handler(value) {
                if (value == undefined) return;
                this.gettableData1(value);
            },
            deep: true
        },
        doInittableData2: {
            handler(value) {
                if (value == undefined) return;
                this.gettableData2(value);
            },
            deep: true
        },
        doInittableData3: {
            handler(value) {
                if (value == undefined) return;
                this.gettableData3(value);
            },
            deep: true
        },
        doInittableData4: {
            handler(value) {
                if (value == undefined) return;
                this.gettableData4(value);
            },
            deep: true
        },
        doInittableData5: {
            handler(value) {
                if (value == undefined) return;
                this.gettableData5(value);
            },
            deep: true
        },
        doInittableData6: {
            handler(value) {
                if (value == undefined) return;
                this.gettableData6(value);
            },
            deep: true
        },

        backFun: {
            handler(value) {
                if (value === null) return;
                this.customBackFun();
                let backFun = [];
                backFun = value.split(',');
                if (backFun.indexOf('rDoInit') >= 0) {
                    let codeTypes = {
                        AAE146:[],
                        AAE145:[],
                        BIC119:[],
                        BIC121:[],
                        BIC120:[],
                        BAE007:[],
                        BAE008:[],
                        BAE009:[],
                        AAZ065:[],

                    };
                    let form = {
                        aic169: {
                            value: '',
                            p: 'H'
                        },
                        bac062: {
                            value: '',
                            p: 'H'
                        },
                        bac063: {
                            value: '',
                            p: 'H'
                        },
                        aic160: {
                            value: '',
                            p: 'R'
                        },
                        aae146: {
                            key: '',
                            value: '',
                            p: 'R'
                        },
                        ljnx: {
                            value: '0-0',
                            p: 'D'
                        },
                        aae160: {
                            key: '',
                            value: '',
                            p: 'R'
                        },
                        aae201: {
                            value: '0-0',
                            p: 'D'
                        },
                        aae200: {
                            value: '0-0',
                            p: 'D'
                        },
                        aae165: {
                            value: '',
                            p: 'D'
                        },
                        aae201: {
                            value: '0-0',
                            p: 'D'
                        },
                        aae200: {
                            value: '0-0',
                            p: 'D'
                        },
                        aic167: {
                            value: '',
                            p: 'D'
                        },
                        aic166: {
                            value: '',
                            p: 'D'
                        },
                        bic119: {
                            key: '',
                            value: '',
                            p: 'R'
                        },
                        bic121: {
                            key: '',
                            value: '',
                            p: 'R'
                        },
                        bic120: {
                            key: '',
                            value: '',
                            p: 'R'
                        },
                        bic126: {
                            value: '',
                            p: 'D'
                        },
                        bic122: {
                            value: '',
                            p: 'R'
                        },
                        bic123: {
                            value: '',
                            p: 'R'
                        },
                        bic124: {
                            value: '',
                            p: 'R'
                        },
                        bic125: {
                            value: '',
                            p: 'R'
                        },
                        aae007: {
                            value: '',
                            p: 'R'
                        },
                        bae011s: {
                            key: '',
                            value: '',
                            p: 'E'
                        },
                        bae012s: {
                            key: '',
                            value: '',
                            p: 'E'
                        },
                        bae013s: {
                            key: '',
                            value: '',
                            p: 'E'
                        },
                        aae006s: {
                            value: '',
                            p: 'E'
                        },
                        aae004: {
                            value: '',
                            p: 'R'
                        },
                        aae005: {
                            value: '',
                            p: 'R'
                        },
                        bae011: {
                            key: '',
                            value: '',
                            p: 'E'
                        },
                        bae012: {
                            key: '',
                            value: '',
                            p: 'E'
                        },
                        bae013: {
                            key: '',
                            value: '',
                            p: 'E'
                        },
                        aae006: {
                            value: '',
                            p: 'E'
                        },
                        aae145: {
                            key: '',
                            value: '',
                            p: 'R'
                        },
                        aaz065: {
                            key: '',
                            value: '',
                            p: 'R'
                        },
                        aae010: {
                            value: '',
                            p: 'R'
                        },
                        aaf002: {
                            value: '',
                            p: 'R'
                        },
                        aae010: {
                            value: '',
                            p: 'R'
                        },
                        bac049: {
                            value: '',
                            p: 'D'
                        },
                        xbfylj: {
                            value: '',
                            p: 'D'
                        },
                        xbfa1: {
                            value: '',
                            p: 'D'
                        },
                        xbfgrylj: {
                            value: '',
                            p: 'D'
                        },
                        xbfa2: {
                            value: '',
                            p: 'D'
                        },
                        xbfgdylj: {
                            value: '',
                            p: 'D'
                        },
                        xbfa3: {
                            value: '',
                            p: 'D'
                        },
                        xbfyylj: {
                            value: '',
                            p: 'D'
                        },
                        lbfylj: {
                            value: '',
                            p: 'D'
                        },
                        lbfa1: {
                            value: '',
                            p: 'D'
                        },
                        lbfgrylj: {
                            value: '',
                            p: 'D'
                        },
                        lbfa2: {
                            value: '',
                            p: 'D'
                        },
                        lbfgdylj: {
                            value: '',
                            p: 'D'
                        },
                        lbfa3: {
                            value: '',
                            p: 'D'
                        },
                        lbfyylj: {
                            value: '',
                            p: 'D'
                        },
                        xlbdylj: {
                            value: '',
                            p: 'D'
                        },
                        xlbda1: {
                            value: '',
                            p: 'D'
                        },
                        xlbdtjj: {
                            value: '',
                            p: 'D'
                        },
                        xlbda2: {
                            value: '',
                            p: 'D'
                        },
                        xlbdyfylj: {
                            value: '',
                            p: 'D'
                        },
                        xlbda3: {
                            value: '',
                            p: 'D'
                        },
                        dnzdylj: {
                            value: '',
                            p: 'D'
                        },
                        dnzda1: {
                            value: '',
                            p: 'D'
                        },
                        yhdylj: {
                            value: '',
                            p: 'D'
                        },
                        yhda2: {
                            value: '',
                            p: 'D'
                        },

                    };
                    let tableData1= {};
                    let tableData2= {};
                    let tableData3= {};
                    let tableData4= {};
                    let tableData5= {};
                    let tableData6= {};
                    let panel= {};

                    let param = {
                        path: this.$route.path,
                        codeTypes:codeTypes,
                        codeTypeFilters: window.btoa(JSON.stringify(this.codeTypeFilters)),
                        form:form,
                        tableData1:tableData1,
                        tableData2:tableData2,
                        tableData3:tableData3,
                        tableData4:tableData4,
                        tableData5:tableData5,
                        tableData6:tableData6,
                        panel:panel

                    };
                    this.$store.dispatch('SET_INIT', param);
                }
            }
        }
    },
    mounted() {
        if (this.$store.getters.cacheData === null) return;
        if (this.$store.getters.cacheData[this.$route.path] === undefined)  return;
        if (this.$store.getters.cacheData[this.$route.path].path !== this.$route.path) return;
        if (this.$store.getters.cacheData[this.$route.path].form !== undefined) {
            this.getformData(this.$store.getters.cacheData[this.$route.path].form);
        }
        if (this.$store.getters.cacheData[this.$route.path].panel !== undefined) {
            this.getpanel(this.$store.getters.cacheData[this.$route.path].panel);
        }
        if (this.$store.getters.cacheData[this.$route.path].tableData1 !== undefined) {
            this.gettableData1(this.$store.getters.cacheData[this.$route.path].tableData1);
        }
        if (this.$store.getters.cacheData[this.$route.path].tableData2 !== undefined) {
            this.gettableData2(this.$store.getters.cacheData[this.$route.path].tableData2);
        }
        if (this.$store.getters.cacheData[this.$route.path].tableData3 !== undefined) {
            this.gettableData3(this.$store.getters.cacheData[this.$route.path].tableData3);
        }
        if (this.$store.getters.cacheData[this.$route.path].tableData4 !== undefined) {
            this.gettableData4(this.$store.getters.cacheData[this.$route.path].tableData4);
        }
        if (this.$store.getters.cacheData[this.$route.path].tableData5 !== undefined) {
            this.gettableData5(this.$store.getters.cacheData[this.$route.path].tableData5);
        }
        if (this.$store.getters.cacheData[this.$route.path].tableData6 !== undefined) {
            this.gettableData6(this.$store.getters.cacheData[this.$route.path].tableData6);
        }

    },
    beforeRouteLeave(to, from, next) {
        let param = {
            path: this.$route.path,
            codeTypes: this.$store.getters.codeTypes,
            codeTypeFilters: window.btoa(JSON.stringify(this.codeTypeFilters)),
            form:this.form,
            tableData1:this.tableData1,
            tableData2:this.tableData2,
            tableData3:this.tableData3,
            tableData4:this.tableData4,
            tableData5:this.tableData5,
            tableData6:this.tableData6,
            panel:this.panel

        };
        if (from) {
            this.$store.dispatch('SET_CACHEDATA', param);
        }
        next();
    },
    methods: {
        getformData(value) {
            this.form = value;
        },
        getpanel(value) {
            this.panel = value;
        },
        gettableData1(value) {
            this.tableData1 = value;
        },
        gettableData2(value) {
            this.tableData2 = value;
        },
        gettableData3(value) {
            this.tableData3 = value;
        },
        gettableData4(value) {
            this.tableData4 = value;
        },
        gettableData5(value) {
            this.tableData5 = value;
        },
        gettableData6(value) {
            this.tableData6 = value;
        },


        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`);
        },
        handleEdit(id) {
            this.dialogFormVisible = true;
        },
        formValidate(value){
            if(value && value.length>0){
                let btn = true;
                value.forEach((item,index)=>{
                    if(!btn) return
                this.$refs[item].validate((valid) => {
                    if (valid) {
                        btn = true;
                    } else {
                        btn = false;
            }
            });
            })
                if(btn) this.$refs.save.btn();
            }
        },

        customBackFun(){//自定义方法体
        },
    },
}
